import { reactive, ref } from 'vue'
import { RequestTheArticle } from '@/api/syxelement.js'
const praiseIoc = ref(false)
const transmitIoc = ref(false)
const collectIoc = ref(false)
const articleArry = reactive({
  arry: []
})
let userid = null
if (window.localStorage.getItem('user')) {
  userid = JSON.parse(window.localStorage.getItem('user')).data.results[0].id
}
// 主方法
export default function getsyxelemntFunction () {
  function praiseIocSwitch (porps) {
    console.log(porps)
    praiseIoc.value = !praiseIoc.value
    if (praiseIoc.value) {
      this.$message({
        type: 'success',
        message: '点赞成功!'
      })
    } else {
      this.$message({
        type: 'info',
        message: '已取消点赞'
      })
    }
  }
  function transmitIocSwitch () {
    transmitIoc.value = !transmitIoc.value
  }
  function collectIocSwitch () {
    collectIoc.value = !collectIoc.value
    if (collectIoc.value) {
      this.$message({
        type: 'success',
        message: '收藏成功!'
      })
    } else {
      this.$message({
        type: 'info',
        message: '已取消收藏'
      })
    }
  }
  // 请求方法
  function requestarticle () {
    RequestTheArticle({
      id: userid
    }).then(res => {
      console.log(res)
      articleArry.arry = res.data.results
    })
  }
  return {
    praiseIoc,
    transmitIoc,
    collectIoc,
    praiseIocSwitch,
    transmitIocSwitch,
    collectIocSwitch,
    requestarticle,
    userid,
    articleArry
  }
}
